﻿using System;
using System.Web.UI;
using Coolite.Ext.Web;
using Pap.Data;
using Pap.Web.Modules.Loan.ViewModel;
using Pap.Web.Utils;
using Utils.UIPermission;

namespace Pap.Web.Modules.Loan.Views
{
    /// <summary>
    /// 
    /// </summary>
    public partial class AssociationsBankAccounts : BasePage<AssociationsBankAccountsViewModel>, IPermittedPage
    {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack && !Ext.IsAjaxRequest)
            {
                this.storeCommitteesBalances.DataSource = this.ViewModel.GetCommitteesBankAccounts();
                this.storeCommitteesBalances.DataBind();
            }
        }

        /// <summary>
        /// Handles the Command event of the gridCommitteesBlances control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Coolite.Ext.Web.AjaxEventArgs"/> instance containing the event data.</param>
        protected void gridCommitteesBlances_Command(object sender, AjaxEventArgs e)
        {
            if (e.ExtraParams["CommandName"] != null)
            {
                if (e.ExtraParams["CommandName"].Equals("ViewDeposites"))
                {
                    this.RedirectFromThisPage("UnionDepositAssociation", new string[] { "CommitteeID=" + e.ExtraParams["CommitteeID"].ToString() });
                }
            }
        }

        /// <summary>
        /// Handles the Clicked event of the btnBack control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="Coolite.Ext.Web.AjaxEventArgs"/> instance containing the event data.</param>
        protected void btnBack_Clicked(object sender, AjaxEventArgs args)
        {
            this.RedirectToPreviousPage();
        }

        public string PermissionName
        {
            get { return Permissions.AssociationsBankAccounts.ToString(); }
        }
    }
}
